package com.gxa.page;

import java.util.List;

public class PageBean {

    //获取
    private List list;
    private long totalrecord;
    private long currentPage;
    private long pagesize;

    //计算
    //总页数
    private long totalPage;
    //前一页
    private long previousPage;
    //下一页
    private long nextPage;


    //计算总页数
    public long getTotalPage() {

        //100  5  20
        //101  5  21
        //99   5  20
        if(this.totalrecord%this.pagesize==0){
            //可以除尽
            this.totalPage=this.totalrecord/this.pagesize;
        }else{
            this.totalPage=this.totalrecord/this.pagesize+1;
        }
        return totalPage;
    }

    //计算前一页
    public long getPreviousPage() {

        //如果当前页在第一页
        if(this.currentPage-1<1){
            this.previousPage=1;
        }else{
            this.previousPage=this.currentPage-1;
        }
        return previousPage;
    }

    //计算下一页
    public long getNextPage() {

        if(this.currentPage+1>getTotalPage()){
            this.nextPage=this.totalPage;
        }else{
            this.nextPage=this.currentPage+1;
        }
        return nextPage;
    }

    public List getList() {
        return list;
    }

    public void setList(List list) {
        this.list = list;
    }

    public long getTotalrecord() {
        return totalrecord;
    }

    public void setTotalrecord(long totalrecord) {
        this.totalrecord = totalrecord;
    }

    public long getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(long currentPage) {
        this.currentPage = currentPage;
    }

    public long getPagesize() {
        return pagesize;
    }

    public void setPagesize(long pagesize) {
        this.pagesize = pagesize;
    }

    @Override
    public String toString() {
        return "PageBean{" +
                "list=" + list +
                ", totalrecord=" + totalrecord +
                ", currentPage=" + currentPage +
                ", pagesize=" + pagesize +
                ", totalPage=" + getTotalPage() +
                ", previousPage=" + getPreviousPage() +
                ", nextPage=" + getNextPage() +
                '}';
    }
}
